﻿using System;
using Chip8.Core.Bus;

namespace Chip8.Core.Processor.Operations
{
	internal class SHR : Operation
	{
		public SHR(int registerIndex)
		{
			RegisterIndex = registerIndex;
		}

		public int RegisterIndex { get; set; }

		public override void Execute(ICPU cpu)
		{
			var carry = cpu.V[RegisterIndex] & 0x1;
			var result = cpu.V[RegisterIndex] >> 1;
			cpu.V[RegisterIndex] = (byte)result;
			cpu.Carry = (byte)carry;
		}
	}
}